<template>
  <div class="search_result"   v-if="show">
    <ul >
      <li v-for="(item,index) in searchResult" :key="index">
        <span class="s1">{{item.type}}</span>
        <span class="s2" @click="jump(item)">
          <a>{{item.bookname}}</a>
        </span>
        <span class="s3" @click="jump2(item)" v-if="item.newChapter!==undefined">
          <a>{{item.newChapter}}</a>
        </span>
        <span class="s4">
          {{item.author}}
        </span>
      </li>

    </ul>

  </div>
</template>
<script>
export default {
  name: 'Li-st',
  props: {
    searchResult: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      show: false
    }
  },

  methods: {
    jump (item) {
      // 点击书名，触发SETNAME函数，将书名传递过去，
      this.$store.commit('SETNAME', item.bookname)
      // 跳转章节内页面
      this.$router.push(`/chapter/${item.href}`)
    },
    jump2 (item) {
      // 点击章节，先触发Setchapter函数，重新获取当前小说的所有章节
      this.$store.dispatch('Setchapter', item)
      // 跳转到内容页面
    }
  },
  watch: {
    searchResult (newval, oldval) {
      // console.log(newval, oldval)
      if (newval.length !== 0) {
        this.show = true
      }
    }

  }
}
</script>
<style lang="less" scoped>
.search_result {
  margin: 15px 0 0 50px;
  width: 695px;
  border: 2px solid #409eff;
  background-color: #E1ECED;
  // width: 75%;
  padding: 0 10px;
  // float: left;
  display: flex;
  ul {
    flex:1;
    list-style: none;
    // float: left;
    padding-inline-start: 0;
    // padding-top: 15px;
    li {
      display: flex;
      padding-top: 15px;
      height: 25px;
      line-height: 25px;
      span {
        font-size: 14px;
        a {
          cursor: pointer;
        }
      }
      .s1 {
        flex: 0.25;
        display: inline-block;
      }
      .s2:hover,
      .s3:hover {
        background-color: pink;
        transition: 1s;
      }
      .s2 {
        // a{
        //     display: inline-block;
        //  width: 250px;
        // }
        flex: 0.6;

        display: inline-block;
      }
      .s3 {
        //  width: 350px;
        display: inline-block;
        flex: 0.8;
      }
      .s4 {
        flex: 0.3;
        text-align: right;
        height: 20px;
        line-height: 20px;
        overflow: hidden;
        // float: right;
      }
    }
  }
}
</style>
